package com.atguigu.guli.service.oss.controller;

import com.atguigu.guli.service.base.result.R;
import com.atguigu.guli.service.oss.service.OssService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

@RestController

@RequestMapping("/admin/oss")
@Slf4j
@Api(tags = "Oss服务模块")
public class AdminOssController {
    @Autowired
    private OssService ossService ;
    //1.上传文件
    @ApiOperation(value = "上传文件")
    @PostMapping("upload")
    public R upload(MultipartFile file,String module) {
        String path = ossService.upload(file, module);
        return R.ok().data("path",path) ;
    }
    //2.删除文件
    @ApiOperation(value = "删除文件")
    @DeleteMapping("delete")
    public R delete(@RequestParam String path,@RequestParam String module) {
        ossService.delete(path, module);
        return R.ok() ;
    }

    @Value("${server.port}")
    private String port ;
    @ApiOperation(value = "openFeign远程调用测试1")
    @PostMapping("test/{username}/{password}")
    public R test(@RequestParam String username,@RequestParam String password) {
        log.error("port {},username {},password {}",port,username,password);
        return R.ok().message("oss服务的响应") ;
    }

    @ApiOperation(value = "openFeign远程调用测试2")
    @PostMapping("test2")
    public R test2(@RequestBody R r) {
        log.error(""+r);
        return R.ok().message("oss服务2的响应") ;
    }

}
